//这个类用来设定邮件的内容，设定一个点击就可以激活用户账号的链接
package common.util.mail;
	
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.ncp.model.entity.registerlogin.UserBasicBean;
	
@SuppressWarnings("serial")
public class sendMailServlet extends HttpServlet {
		public void doGet(HttpServletRequest request, HttpServletResponse response)
				throws ServletException, IOException {
			response.setContentType("text/html");
			this.doPost(request, response);
		}
	
		public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
	
				response.setContentType("text/html");
				response.setCharacterEncoding("UTF-8");
				UserBasicBean UserBasic = (UserBasicBean)request.getSession().getAttribute("userRegisterInfo");
				String path = request.getContextPath();
				String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
				String toAddress=UserBasic.getEmail();
				String userLoginName=UserBasic.getUserLoginName();
				String ActiveCode=UserBasic.getActiveCode();
				//String userId=String.valueOf(UserBasic.getUserID());
				//String time=UserBasic.getRegisterDate();
				MailSenderInfo mailInfo = new MailSenderInfo();
				mailInfo.setMailServerHost("smtp.126.com");
				mailInfo.setMailServerPort("25");
				mailInfo.setValidate(true);
				mailInfo.setUserName("nongchanpinxm@126.com");
				mailInfo.setPassWord("2012904");//您的邮箱密码　　　 
				mailInfo.setFromAddress("nongchanpinxm@126.com");
				mailInfo.setToAddress(toAddress);
				mailInfo.setSubject("农产品项目组");
				String content="<p>感谢您注册我们的农产品网站，点击下面的链接即可完成注册：<p><br>"
					+"<a href="+basePath+"registerActiveServlet?ActiveCode="+ActiveCode+">"+basePath+"registerActiveServlet?ActiveCode="+ActiveCode+"</a>"
					+"</p><br>"
								+"(如果链接无法点击，请将它拷贝到浏览器的地址栏中)<br>"
								+"您的登录账号是："+userLoginName;
				mailInfo.setContent(content);		 			
				//这个类主要来发送邮件
				SimpleMailSender sms = new SimpleMailSender();
				//sms.sendTextMail(mailInfo);//发送文本格式的邮件
				sms.sendHtmlMail(mailInfo);//发送html格式的邮件
				request.getRequestDispatcher("pages/registerlogin/mainIdentification.jsp").forward(request, response);
			}
		}